<!--
Copyright 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->

<link rel="import" href="ct-button.html">
<link href="../bower_components/core-tooltip/core-tooltip.html" rel="import">
<link href="../bower_components/core-icon-button/core-icon-button.html" rel="import">
<link href="../bower_components/paper-dialog/paper-action-dialog.html" rel="import">
<link href="../bower_components/paper-dialog/paper-dialog-transition.html" rel="import">

<polymer-element name="ct-master-failure-card" attributes="group currentTrooper">
  <template>
    <style>
      :host {
        display: block;
      }
      .message {
        margin-bottom: 10px;
        font-weight: bold;
        color: red;
      }
      div[tip] {
        color: white;
        font-size: 9pt;
        line-height: 1.5em;
      }
      core-icon-button {
        color: red;
      }
    </style>
      <div class="message">
        <a href="{{ group.failure.masterUrl }}">{{ group.failure.masterUrl }}</a>
        <span id="masterAlert">master data {{ group.failure.hoursSinceLastUpdate }} hours stale.</span>
        <core-icon-button icon="info" on-tap="{{ toggleHelp }}"></core-icon-button>
      </div>
      <paper-action-dialog heading="About stale master data" id="helpDialog" transition="paper-transition-center">
        <div>
          We weren't able to get up to date information from the master.<br/>
          This can mean the master is down, or (more often) that it's overloaded and having trouble
          serving up the JSON about it's current state.<br/>
          Something is wrong with the master and needs to be fixed ASAP, since it means that sheriff-o-matic 
          has no idea about the state of the tree on this master.<br/>
          Things to check:
          <ul>
            <li><a href="https://uberchromegw.corp.google.com/i/chromium.infra.cron/builders/builder-alerts">Latest builder_alerts run</a></li>
            <li>Check the <a href="{{ group.failure.masterUrl }}">master itself</a> - it may be down.</li>
            <li>Check the Appengine logs for <a href="//chrome-build-extract.appspot.com"> chrome-build-extract.appspot.com</a> - it may be having problems caching this data from the master.</li>
            <li>Instructions for <a href="https://x20web.corp.google.com/teams/chrome-infra/doc/html/playbook.html#restarting-a-buildbot-master-process">restarting masters</a> if all else fails.</li>
          </ul>
          <template if="{{ currentTrooper }}">
            <p>
              Latest trooper according to the rotation calendar is: <a target='_blank' href='mailto:{{currentTrooper}}@google.com'>{{ currentTrooper }}@google.com</a>
            </p>
          </template>
          See <a href="https://sites.google.com/a/chromium.org/dev/developers/testing/contacting-a-trooper">Contact a Trooper</a> for further help.
        </div>
        <ct-button label="OK" affirmative id="dialogOk"></ct-button>
      </paper-action-dialog>
  </template>
<script>
  Polymer({
    curretTrooper : 'unknown',
    toggleHelp: function() {
      this.$.helpDialog.toggle();
    },
    created: function() {
      var rot = CTRotations.getInstance();
      var today = new Date().toISOString().substr(0, 10);
      this.currentTrooper = rot.getOncaller(today, 'troopers');
    }
  });
</script>
</polymer-element>


